from flask.cli import with_appcontext
import click
from .extensions import db

@click.command()
@click.option('--drop',is_flag=True,help='create after drop')
@with_appcontext
def initdb(drop):
    '''database initialization'''
    #命令行输入flask initdb, 将初始化数据库
    #命令行输入flask initdb --drop, 将重建数据库
    if drop:
        click.confirm('This operation will clear the database, do you want to continue?', abort=True)
        db.drop_all()
        click.echo('Drop tables.')
    db.create_all()
    click.echo('Initialized database.')